package com.lfx.concurrent;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;

public class CompletTableFutureMain6 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> stringCompletableFuture1 = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "返回结果";
        }).thenCompose(new Function<String, CompletionStage<Integer>>() {
            @Override
            public CompletionStage<Integer> apply(String s) {
                return CompletableFuture.supplyAsync(()->{
                        return 111;
                });
            }
        });

        Integer s = stringCompletableFuture1.get();
        System.out.println("result"+s );

    }
}
